<template>
  <div class="index">
    <iframe
      :src="url"
      width="100%"
      height="100%"
      class="orders_iframe"
    />
  </div>
</template>

<script>
	export default {
		name: "Index",
		components: {},
		data() {
			return {
				url: 'https://mall.inja.com/inja/shop/index.html',
				html: ''
			}
		},
		mounted() {
			if (localStorage.getItem("token")) {
				console.log("token有效");
				this.url = this.url + '?token=' + localStorage.getItem("token")
			} else {
				this.GetCsLogin();
			}
		},
		methods: {
			GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r !== null) return unescape(r[2]);
				return null;
			},
			GetCsLogin() {
				let params = {
					ticket: this.GetQueryString("ticket"),
				};
				if (params.ticket) {
					this.$api.home.casLogin(params).then((res) => {
						console.log("单点登录", res.data);
						if (res.code !== 1) {
							this.$message.error(res.msg);
						} else {
							localStorage.setItem("token", res.data.token);
							this.url = this.url + '?token=' + res.data.token
							localStorage.setItem("userInfo", JSON.stringify(res.data.user));
						}
						// localStorage.setItem("token",res.data)
					});
				}
			}
		}
	}
</script>

<style>
	.index {
		width: 100%;
		height: 100vh;
	}

	.orders_iframe {
		width: 100%;
		height: 100%;
	}
</style>
